package com.itheima.reflect.test;

import java.lang.reflect.Field;

public class Tool {

	//此方法可将obj对象中名为propertyName的属性的值设置为value
	public void setProperty(Object obj, String propertyName, Object value) throws Exception {
		Class<? extends Object> clazz = obj.getClass(); // 获取字节码对象
		Field f = clazz.getDeclaredField(propertyName); // 暴力反射获取字段
		f.setAccessible(true);
		f.set(obj, value);
	}
}
